﻿module Sustainalytics.EsgRatings.Admin {

    import Common = Sustainalytics.Common;
    import CommonAdmin = Sustainalytics.Common.Admin;

    export class TestingESGBackEndService  {

        private $q: ng.IQService;
        private $http: ng.IHttpService;
        private notificationFactory: Common.INotificationFactory;
        private staticObjectsAdmin: CommonAdmin.IStaticObjects;
        private $location: ng.ILocationService;
     
        constructor(
            $q: ng.IQService,
            $http: ng.IHttpService,
            $location: ng.ILocationService,
            notificationFactory: Common.INotificationFactory,
            staticObjectsAdmin: CommonAdmin.IStaticObjects) {

            var ctx = this; 
            ctx.$q = $q;
            ctx.$http = $http;
            ctx.notificationFactory = notificationFactory;
            ctx.staticObjectsAdmin = staticObjectsAdmin;
            ctx.$location = $location;
        }
        
        public getTestESGSetUpData(): ng.IPromise<TestESGRatingOutDto> {

            var ctx = this;

            // MOCK DATA
            //var result = 
            //    {
            //        ListCompanies:
            //        [
            //            { id: "1", name: "one" }, { id: "2", name: "two" }, { id: "3", name: "three" }, { id: "4", name: "four" },
            //            { id: "5", name: "five" }, { id: "6", name: "six" }, { id: "7", name: "seven" }, { id: "8", name: "eight" }
            //        ],
            //        ListIndustryGroups:     [{ id: "1", name: "ind one" }, { id: "2", name: " ind two" }, { id: "3", name: "ind three" }, { id: "4", name: "ind four" }],
            //        ListPeerGroups:         [{ id: "1", name: "peer one" }, { id: "2", name: " peer two" }, { id: "3", name: "peer three" }, { id: "4", name: "peer four" }],
            //        ListReferenceUniverses: [{ id: "1", name: "ref univ one" }, { id: "2", name: "ref univ two" }, { id: "3", name: "ref univ three" }, { id: "4", name: "ref univ four" }],
            //        ListWeightMatrixes:     [{ id: "1", name: "Default Weight Matrix" }],
            //    };
            //var def = ctx.$q.defer();
            //def.resolve(result);

            //return def.promise;


            return this.$http.get(ctx.listsUrl());
        }    
        
        private listsUrl(): string {
            var ctx = this;
            return ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() +
                "/esgratingserv/api/v1/esgratingsfilter/";
        }  
    }


    var mod = angular.module(esgRatingsAdminModuleName);

    // register service with EsgRatings Angular module
    mod.service('TestingESGBackEndService',
        ['$q', '$http', '$location', 'notificationFactory', 'staticObjectsAdmin', TestingESGBackEndService]);
}